#include "config.h"

#ifdef ENABLE_ORACLE

#include "OracleDatabase.h"

using namespace std;
/*string query = "SELECT 1";

    OCIEnv *environment;
    OCISvcCtx *serviceContext;
    OCIError *error;
    OCIStmt *statement;
    OCIDefine *define;

    OCIInitialize(OCI_DEFAULT, NULL, NULL, NULL, NULL);

    OCIEnvInit(&environment, OCI_DEFAULT, 0, NULL);
    OCIEnvInit(&environment, OCI_DEFAULT, 0, NULL);

    OCIHandleAlloc(environment, (dvoid **)&error, OCI_HTYPE_ERROR, (size_t) 0, NULL);

    OCILogon(environment, error, &serviceContext, (const unsigned char*)username.c_str(), username.size(), (const unsigned char*)password.c_str(), password.size(),  (const unsigned char*)database.c_str(), database.size());

    OCIHandleAlloc(environment, (dvoid **)&statement, OCI_HTYPE_STMT, 0, NULL);


    if(OCI_SUCCESS == OCIStmtPrepare(statement, error, (const unsigned char*)query.c_str(), query.size(), OCI_NTV_SYNTAX, OCI_DEFAULT))
    {
            if(OCI_SUCCESS == OCIStmtExecute(serviceContext, statement, error, 1, 0, NULL, NULL, OCI_COMMIT_ON_SUCCESS))
            {
                cout << "error 1" << endl;
            }
    }

    OCILogoff(serviceContext, error);
    OCIHandleFree(error, OCI_HTYPE_ERROR);
    OCIHandleFree(environment,OCI_HTYPE_ENV);

    environment = 0;
    error = 0;
    serviceContext = 0;*/
OracleDatabase::OracleDatabase (PString host, PString port, PString database, PString username, PString password): Database(host, port, database,username, password){

}

OracleDatabase::~OracleDatabase() {
    OCILogoff(this->server_context, this->error);
    OCIHandleFree(this->error, OCI_HTYPE_ERROR);
    OCIHandleFree(this->env,OCI_HTYPE_ENV);

    this->env = 0;
    this->error = 0;
    this->server_context = 0;
}

PQuery OracleDatabase::query(string sqlQuery)
{
    return new OracleQuery(this, this->database, sqlQuery);
}

tableInfo OracleDatabase::getTableInfoOf(string database, string schema, string table);
{
	struct tableInfo info;
	return info;
}

PQuery OracleDatabase::listDatabases() {
    return this->query("");
}

PQuery OracleDatabase::listTables(string database, string schema) {
    return this->query("");
}


PQuery OracleDatabase::listTables(string database, string schema) {
    return this->query("");
}

string OracleDatabase::escapeString(string str) {

}

OracleQuery::OracleQuery(OracleDatabase *dbc, PString database, PString sqlQuery) : AbstractQuery(dbc, database, sqlQuery) {
{

}

OracleQuery::~OracleQuery()
{

}


PDataRow OracleQuery::fetch()
{
    for(unsigned int i = 0; i < 10; i++)
    {

    }
}

#endif
